package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.escool.model.TbCatMateriaTemp;
import com.escool.model.TbCatMateriaTempDet;
@Repository
public class CatMateriaTempDAOImpl implements CatMateriaTempDAO {

	@Autowired
	SessionFactory sessionFactoyr;
	
	@Override
	public void addTbCatMateriaTemp(TbCatMateriaTemp TbCatMateriaTemp) {
		// TODO Auto-generated method stub
		sessionFactoyr.getCurrentSession().save(TbCatMateriaTemp);
	}

	@Override
	public void editTbCatMateriaTemp(TbCatMateriaTemp TbCatMateriaTemp) {
		// TODO Auto-generated method stub
		sessionFactoyr.getCurrentSession().update(TbCatMateriaTemp);	
	}

	@Override
	public void delTbCatMateriaTemp(int id) {
		// TODO Auto-generated method stub
		TbCatMateriaTemp cobro = (TbCatMateriaTemp) sessionFactoyr.getCurrentSession().load(TbCatMateriaTemp.class,id);
		if(cobro != null){
			sessionFactoyr.getCurrentSession().delete(cobro);
		}
	}

	@Override
	public List<TbCatMateriaTemp> listTbCatMateriaTemp() {
		// TODO Auto-generated method stub
		String hql = "from TbCatMateriaTemp";
		return sessionFactoyr.getCurrentSession().createQuery(hql).list();
	}

	@Override
	public TbCatMateriaTemp findTbCatMateriaTemp(int id) {
		// TODO Auto-generated method stub
		return (TbCatMateriaTemp)sessionFactoyr.getCurrentSession().get(TbCatMateriaTemp.class, id);
	}

	@Override
public void addTbCatMateriaTempDet(TbCatMateriaTempDet TbCatMateriaTempDet) {
// TODO Auto-generated method stub
sessionFactoyr.getCurrentSession().save(TbCatMateriaTempDet);
}

@Override
public void editTbCatMateriaTempDet(TbCatMateriaTempDet TbCatMateriaTempDet) {
// TODO Auto-generated method stub
sessionFactoyr.getCurrentSession().update(TbCatMateriaTempDet);	
}

@Override
public void delTbCatMateriaTempDet(int id) {
// TODO Auto-generated method stub
TbCatMateriaTempDet cobro = (TbCatMateriaTempDet) sessionFactoyr.getCurrentSession().load(TbCatMateriaTempDet.class,id);
if(cobro != null){
	sessionFactoyr.getCurrentSession().delete(cobro);
}
}

@Override
public List<TbCatMateriaTempDet> listTbCatMateriaTempDet(int idMaestro) {
// TODO Auto-generated method stub
String hql = "from TbCatMateriaTempDet where tbCatMateriaTemp.idMateriaTemp="+idMaestro;
return sessionFactoyr.getCurrentSession().createQuery(hql).list();
}

@Override
public TbCatMateriaTempDet findTbCatMateriaTempDet(int id) {
// TODO Auto-generated method stub
return (TbCatMateriaTempDet)sessionFactoyr.getCurrentSession().get(TbCatMateriaTempDet.class, id);
}

}
